var app = require('express');
var router = app.Router();
var socket_io = require('socket.io');

router.prepareSocketIO = function (server) {
    var io = socket_io.listen(server);

    io.sockets.on('connection', function (socket) {

        socket.on('refer', function (msg) {
            socket.emit('refer_front_end', msg);
            socket.broadcast.emit('refer_front_end', msg);
        });

        socket.on('disconnection', function (data) {
            socket.disconnect(true);
        });

        socket.on('stateChange', function (mid,data) {

            socket.emit('notify_state_change', mid, data);
            socket.broadcast.emit('notify_state_change', mid, data);
        });
    });


};

module.exports = router;
